package com.fhz.day009;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

import androidx.annotation.Nullable;

/**
 * 时间:2022/4/28
 *
 * @author msfeng
 * 简述: TODO
 */
public class MyOpenHelper extends SQLiteOpenHelper {

    private static final String TAG = "feng";
    /**
     *
     * @param context 上下文
     * @param name  数据库的名称
     * @param factory null
     * @param version 1 只能越来越高,不能低
     */
    public MyOpenHelper(@Nullable Context context, @Nullable String name, @Nullable SQLiteDatabase.CursorFactory factory, int version) {
        super(context, name, factory, version);
    }

    /**
     * 只执行一次
     * @param db
     */
    @Override
    public void onCreate(SQLiteDatabase db) {
        //创建库同时,也可以创建一个表.
        Log.i(TAG, "onCreate: ");
        db.execSQL("create table user(id integer primary key autoincrement,name vachar(20),age integer)");
    }

    /**
     * 版本变化的时候执行
     * @param db
     * @param oldVersion
     * @param newVersion
     */
    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        Log.i(TAG, "onUpgrade: ");
    }
}

